package com.cch.cooperation.api.zone.controller;

import com.cch.cooperation.api.auth.dto.LoginUserDTO;
import com.cch.cooperation.api.common.request.IdReq;
import com.cch.cooperation.api.zone.dto.*;
import com.cch.cooperation.api.zone.service.ZoneRemindServiceImpl;
import com.cch.cooperation.common.web.response.Response;
import com.cch.cooperation.common.web.session.Session;
import com.cch.cooperation.common.web.session.SessionManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "空间提醒事项接口")
@RestController
@RequestMapping("/api/zone/remind")
public class ZoneRemindController {

    @Resource
    private ZoneRemindServiceImpl zoneRemindService;
    @Resource
    private SessionManager sessionManager;

    @ApiOperation("添加提醒")
    @PostMapping("/add")
    public Response<ZoneRemindDTO> add(@RequestBody ZoneRemindAddDTO req) {
        Session<LoginUserDTO> session = sessionManager.get();
        req.setCreateUserId(session.getData().getId());
        ZoneRemindDTO data = zoneRemindService.add(req);
        return Response.success(data);
    }

    @ApiOperation("修改提醒")
    @PostMapping("/updateById")
    public Response<ZoneRemindDTO> updateById(@RequestBody ZoneRemindUpdateDTO req) {
        Session<LoginUserDTO> session = sessionManager.get();
        req.setCreateUserId(session.getData().getId());
        ZoneRemindDTO data = zoneRemindService.updateById(req);
        return Response.success(data);
    }

    @ApiOperation("根据id删除")
    @PostMapping("/deleteById")
    public Response<Void> deleteById(@RequestBody IdReq req) {
        zoneRemindService.deleteById(req.getId());
        return Response.success();
    }

    @ApiOperation("获取首页提醒列表")
    @PostMapping("/getHomeList")
    public  Response<ZoneRemindHomeDTO> getHomeList(@Valid @RequestBody ZoneRemindHomeQueryDTO query) {
        Session<LoginUserDTO> session = sessionManager.get();
        query.setUserId(session.getData().getId());
        ZoneRemindHomeDTO data = zoneRemindService.getHomeList(query);
        return Response.success(data);
    }

    @ApiOperation("查询提醒列表")
    @GetMapping("/queryList")
    public Response<List<ZoneRemindDTO>> queryList(ZoneRemindQueryDTO query) {
        Session<LoginUserDTO> session = sessionManager.get();
        query.setUserId(session.getData().getId());
        List<ZoneRemindDTO> data = zoneRemindService.queryList(query);
        return Response.success(data);
    }

    @ApiOperation("完成事项")
    @PostMapping("/completeById")
    public Response<Void> completeById(@RequestBody ZoneRemindCompleteDTO req) {
        zoneRemindService.completeById(req);
        return Response.success();
    }

    @ApiOperation("取消完成事项")
    @PostMapping("/cancelCompleteById")
    public Response<Void> cancelCompleteById(@RequestBody IdReq req) {
        zoneRemindService.cancelCompleteById(req.getId());
        return Response.success();
    }

    @ApiOperation("根据id查询提醒详情")
    @GetMapping("/getById")
    public Response<ZoneRemindDTO> getById(@RequestParam(value = "id") String id) {
        Session<LoginUserDTO> session = sessionManager.get();
        ZoneRemindDTO data = zoneRemindService.getById(id, session.getData().getId());
        return Response.success(data);
    }
}
